Skip to content

test: enhance resource reading tests #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

tzolov
Copy link
Contributor

@tzolov tzolov commented Jun 15, 2025

  • Implement comprehensive resource content validation for text/plain and application/octet-stream MIME types
  • Validate resource count expectations (10 resources)
  • Add elicitation capability testing with ElicitRequest/ElicitResult support
  • Clean up unused imports (ObjectMapper, ImageFromDockerfile)

- Implement comprehensive resource content validation for text/plain and application/octet-stream MIME types
- Validate resource count expectations (10 resources)
- Add elicitation capability testing with ElicitRequest/ElicitResult support
- Clean up unused imports (ObjectMapper, ImageFromDockerfile)

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
… 10 sec

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
@@ -424,6 +445,20 @@ void testInitializeWithSamplingCapability() {
});
}

@Test
void testInitializeWithElicitationCapability() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to the ReadResources, but discovered a missing elicitation aync testing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you - I'll be sure to double-check this in other PRs 😓

Comment on lines +347 to +351
withClient(createMcpTransport(), client -> {
Flux<McpSchema.ReadResourceResult> resources = client.initialize()
.then(client.listResources(null))
.flatMapMany(r -> Flux.fromIterable(r.resources()))
.flatMap(r -> client.readResource(r));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to not test this (and the others) with a cursor, even in the actual listResources tests? Testing a single page ensures we can read individual resource types, but we're still missing coverage on how valid pagination tokens are handled.

Possibly related to #306 (maybe we need a shared, well-tested listAllResources or similar).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid point. As you've noticed we don't have complete/proper pagination implementation. Feel free to jump on this if interested.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added support for listAllResources as part of #306 as well. That should hopefully help out for such usecases in the future.

@LucaButBoring
Copy link
Contributor

Looks great, just left a small question on pagination.

assertThat(resources.resources()).isNotNull();

if (resources.resources().isEmpty()) {
throw new IllegalStateException("No resources available for testing readResource functionality");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this and the above be replaced with assertThat(resources.resources()).isNotNull().isNotEmpty(); ?

@@ -330,18 +337,72 @@ void testReadResourceWithoutInitialization() {

@Test
void testReadResource() {
AtomicInteger readResourceCount = new AtomicInteger(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a synchronous test, can this be a regular int?

throw new IllegalArgumentException("Unexpected content type: " + content.mimeType());
}
});
}).expectNextCount(9).verifyComplete();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of only validating one result and checking the count of the remainder, consider something like

.recordWith(ArrayList::new)
.consumeRecordedWith(items -> {
    // assertThat(items)...
})

@@ -122,9 +129,9 @@ <T> void verifyNotificationSucceedsWithImplicitInitialization(Consumer<McpSyncCl

<T> void verifyCallSucceedsWithImplicitInitialization(Function<McpSyncClient, T> blockingOperation, String action) {
withClient(createMcpTransport(), mcpSyncClient -> {
StepVerifier.create(Mono.fromSupplier(() -> blockingOperation.apply(mcpSyncClient))
// Offload the blocking call to the real scheduler
.subscribeOn(Schedulers.boundedElastic())).expectNextCount(1).verifyComplete();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a mistake. Will revert it

tzolov added 2 commits June 17, 2025 17:06
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Copy link
Member

@chemicL chemicL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow-up! I guess we still need to resolve the conflicts.

tzolov added a commit that referenced this pull request Jun 18, 2025
- Implement comprehensive resource content validation for text/plain and application/octet-stream MIME types
- Validate resource count expectations (10 resources)
- Add elicitation capability testing with ElicitRequest/ElicitResult support
- Clean up unused imports (ObjectMapper, ImageFromDockerfile)

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
@tzolov tzolov modified the milestone: 0.11.0 Jun 18, 2025
@tzolov
Copy link
Contributor Author

tzolov commented Jun 18, 2025

Rebased, resolved conflict, squashed and merged at b701a36

@tzolov tzolov closed this Jun 18, 2025
pantanurag555 pushed a commit to pantanurag555/java-sdk that referenced this pull request Jun 23, 2025
- Implement comprehensive resource content validation for text/plain and application/octet-stream MIME types
- Validate resource count expectations (10 resources)
- Add elicitation capability testing with ElicitRequest/ElicitResult support
- Clean up unused imports (ObjectMapper, ImageFromDockerfile)

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants